var mongoose = require("mongoose");
// let url = "mongodb://121.199.175.151:27017/medical";
let url = "mongodb://medical:wekC8aW4GKNM8ThM@121.199.175.151:27017/medical";

mongoose.connect(url, (err) => {
  if (!err) {
    console.log("连接成功,运行端口:3461");
  }
});

const Schema = mongoose.Schema;

var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var formattedTime = year + '/' + month + '/' + day + ' ' + hour + ':' + minute;
// console.log(formattedTime);
/** 管理员列表*/
const AdminSchema = new Schema({
  username: String,
  pwd: String,
  roles: String,
  photo: String, // 人脸图片
  end_chat:{
    type:String,
    default:''
  },//最后一条聊天记录
  end_date:{
    type:String,
    default:formattedTime
  },//最后聊天的时间
});

const AdminModel = mongoose.model("admin", AdminSchema);
// 故障码
const GzmdaSchema = new Schema({
  cx: String,
  bz: String,
  kzq: String,
  spn: String,
  fmi: String,
  ms: String,
  dj: String
});

const GzmdaModel = mongoose.model("gzmda", GzmdaSchema);




const Text = new Schema({
  username: String,
  pwd: String,
  roles: String,
  photo: String, // 人脸图片
});

const TextModel = mongoose.model("Text", Text);


module.exports = {
  AdminModel,
  GzmdaModel,
  TextModel,
  mongoose
};
